import wizard
import pooler
from tools.misc import UpdateableStr,UpdateableDict
import time
import operator
from osv import osv, fields
from osv.orm import intersect
import tools.sql
from tools import config
from tools.translate import _
from mx import DateTime

class wizard_contract_to_client_pdf(wizard.interface):
   
    def _get_records(self, cr, uid, data, context={}):
        pool = pooler.get_pool(cr.dbname)
        ids=[]
        check=False
        ctc_report_obj=pool.get("kdvn.report.contract.to.client")
        try:
            ctc_ids=data['ids']
            check=True
        except:
            ctc_ids=data['id']
        if ctc_ids:
            ctc_report_ids=ctc_report_obj.search(cr,uid,[('contract_id','in',ctc_ids)])
#            list_ctc=.browse(cr,uid,ctc_ids)
#            for x in list_ctc:
#                if x.contract_id:
#                    ids.append(x.contract_id.id)
        data['ids']=ctc_report_ids
        data['model']='kdvn.report.contract.to.client'
        if ctc_report_ids:
            data['id']=ctc_report_ids[0]
        return {'ids' : ctc_report_ids,'id':data['id'],'model':'kdvn.report.contract.to.client', 'title' : 'Contract To Client Report'} 
        
    states = {
           'init': {
            'actions': [_get_records],
            'result': {
                'type': 'print',
                'name' : 'Contract to Client',
                'report': 'kdvn.contract.to.client.report',
                #'rml' : 'account_analytic_summary/report/progress_evaluation_sheet.jrxml',
                'state': 'end'
            },
        },
    }
wizard_contract_to_client_pdf('jreports.contract_to_client_pdf')

#class wizard_contract_to_client_excel(wizard.interface):
#   
#    def _get_records(self, cr, uid, data, context={}):
#        pool = pooler.get_pool(cr.dbname)
#        ids=[]
#        check=False
#        ctc_report_obj=pool.get("kdvn.report.contract.to.client")
#        try:
#            ctc_ids=data['ids']
#            check=True
#        except:
#            ctc_ids=data['id']
#        if ctc_ids:
#            ctc_report_ids=ctc_report_obj.search(cr,uid,[('contract_id','in',ctc_ids)])
##            list_ctc=.browse(cr,uid,ctc_ids)
##            for x in list_ctc:
##                if x.contract_id:
##                    ids.append(x.contract_id.id)
#        data['ids']=ctc_report_ids
#        data['model']='kdvn.report.contract.to.client'
#        if ctc_report_ids:
#            data['id']=ctc_report_ids[0]
#        return {'ids' : ctc_report_ids,'id':data['id'],'model':'kdvn.report.contract.to.client', 'title' : 'Contract To Client Report'} 
#        
#    states = {
#           'init': {
#            'actions': [_get_records],
#            'result': {
#                'type': 'print',
#                'name' : 'Contract to Client',
#                'report': 'kdvn.contract.to.client.report.excel',
#                #'rml' : 'account_analytic_summary/report/progress_evaluation_sheet.jrxml',
#                'state': 'end'
#            },
#        },
#    }
#wizard_contract_to_client_excel('jreports.contract_to_client_excel')